package org.infinitest.intellij;

import org.infinitest.intellij.idea.facet.FacetListener;
import org.infinitest.intellij.idea.facet.InfinitestFacet;
import org.infinitest.intellij.idea.facet.InfinitestFacetConfiguration;
import org.infinitest.intellij.idea.facet.InfinitestFacetType;
import org.jmock.Expectations;
import org.jmock.Mockery;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;

public class WhenAddingFacetToModule
{
  private Mockery mockery = new Mockery();
  private FacetListener listener;
  private StartDetectingInfinitestToolWindow window;

  @Before
  public void setUp()
  {
    window = new StartDetectingInfinitestToolWindow(null, new ModuleStub("test"));
  }

  @Test
  public void shouldStartInfinitestIfProjectOpened()
  {
    window.projectOpened();
    assertFalse(window.isStarted());

    window.facetInitialized();
    assertTrue(window.isStarted());
  }

  @Test
  public void shouldNotStartInfinitestIfProjectNotOpened()
  {
    window.facetInitialized();
    assertFalse(window.isStarted());
  }

  @Test
  public void shouldNotifyFacetListeners()
  {
    listener = mockery.mock(FacetListener.class);
    mockery.checking(new Expectations()
    {
      {
        one(listener).facetInitialized();
      }
    });

    InfinitestFacet facet = new InfinitestFacet(InfinitestFacetType.INSTANCE, new ModuleStub("test", listener), null,
      new InfinitestFacetConfiguration(), null);

    facet.initFacet();

    mockery.assertIsSatisfied();
  }
}
